package kafka

import zio.*
import zio.kafka.producer.*
import zio.kafka.serde.*

object KafkaProducerHelper {

  val kafkaProducerSettings: ProducerSettings = ProducerSettings(
    bootstrapServers = List("10.8.0.5:29093")
  )

  val producer: ZLayer[Any, Throwable, Producer] =
    ZLayer.scoped(Producer.make(kafkaProducerSettings))

  def produceMessage(topic: String, key: String, value: String): RIO[Producer, Unit] =
    Producer
      .produce(
        topic = topic,
        key = key,
        value = value,
        keySerializer = Serde.string,
        valueSerializer = Serde.string
      )
      .unit
}
